<?php 
namespace app\admin\controller;
class Config extends Common {

	function index(){
		if (\Ebcms::isPost()) {
			$configs = \mylib\Input::post('configs');
			if ($configs && is_array($configs)) {
				foreach ($configs as $id => $value) {
					\Ebcms::db() -> update('config', [
						'value'=>$value
					], [
						'id'=>$id
					]);
				}
			}
			\mylib\Cache::delete('configs');
			return $this -> success('提交成功！', \mylib\Route::buildUrl('/admin/config/index'));
		}else{
			$tmp = \Ebcms::db() -> select('config', '*', [
				'ORDER' => [
					'weight' => 'ASC',
					'id' => 'ASC',
				]
			]);
			$configs = [];
			foreach ($tmp as $key => $value) {
				if (!isset($configs[$value['group']])) {
					$configs[$value['group']] = [];
				}
				$configs[$value['group']][] = $value;
			}
			$this -> assign('configs', $configs);
			return $this -> html($this -> fetch());
		}
	}
}